home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Image Compendium
/
Image Compendium.iso
/
viewer
/
mac
/
fixer.sit
/
fixer.c
next >
Wrap
C/C++ Source or Header
|
1990-03-14
|
3KB
|
137 lines
/*
* fixer.c - Steve Hawley 3/90
* sdh@flash.bellcore.com
* fixer will patch PICT files created by Giffer 1.03 so that they can
* be displayed in Studio 8, or Image etc.
*
* The problem with giffer is that it redefines white and black (positions 0 and
* 255 in the colormap). This is a bad thing to do, and confuses the heck out of
* the poor Macintosh.
*
* Fixer takes a stupid, but quick means at patching the files. It copies the
* file, coercing color 0 to be white and color 255 to be black. It doesn't parse
* the PICT file, so it won't work on anything but those created by Giffer 1.03.
* ie, I've only tested it on 1.03 --it might work on other versions, but don't
* hold your breath.
*/
main()
{
int inRef, outRef;
InitGraf(&thePort);
InitFonts();
InitWindows();
TEInit();
InitMenus();
InitDialogs(0L);
SetCursor(&arrow);
while((inRef = PickLoad()) != -1) {
if ((outRef = PickSave()) != -1) {
Thrash(inRef, outRef);
FSClose(inRef);
FSClose(outRef);
}
}
}
PickLoad()
{
static Point p = { 100, 100 };
SFReply myReply;
static OSType myTypes[] = {
'PICT'
};
int fRef;
SFGetFile(p, "\PWhich file?", 0L, sizeof(myTypes)/sizeof(OSType), myTypes,
0L, &myReply);
if (myReply.good) {
if (FSOpen(myReply.fName, myReply.vRefNum, &fRef)) return(-1);
else return(fRef);
}
return(-1);
}
PickSave()
{
static Point p = { 100, 100 };
int fRef;
SFReply myReply;
myReply.fType = 'PICT';
SFPutFile(p, "\PSave as:", "\p", 0L, &myReply);
if (myReply.good) {
Create(myReply.fName, myReply.vRefNum, '????', 'PICT');
if (FSOpen(myReply.fName, myReply.vRefNum, &fRef)) return(-1);
else return(fRef);
}
else return(-1);
}
Thrash(from, to)
int from, to;
{
Ptr data;
long size, fileEOF, currMark, dataSize;
register int i;
register unsigned char *p;
struct {
unsigned int r, g, b;
} rgb;
size = 624; /* 624 is the offset until 1st entry in colormap */
data = NewPtr(size);
FSRead(from, &size, data);
size = 624;
FSWrite(to, &size, data);
DisposPtr(data);
size = sizeof(rgb);
FSRead(from, &size, &rgb);
rgb.r = 0xffff; /* force white */
rgb.g = 0xffff;
rgb.b = 0xffff;
size = sizeof(rgb);
FSWrite(to, &size, &rgb);
size = 2034; /* offset to last entry in rgb table */
data = NewPtr(size);
FSRead(from, &size, data);
size = 2034;
FSWrite(to, &size, data);
DisposPtr(data);
size = sizeof(rgb);
FSRead(from, &size, &rgb);
rgb.r = 0; /* force black */
rgb.g = 0;
rgb.b = 0;
size = sizeof(rgb);
FSWrite(to, &size, &rgb);
size = 18; /* offset to data start */
data = NewPtr(size);
FSRead(from, &size, data);
size = 18;
FSWrite(to, &size, data);
DisposPtr(data);
GetFPos(from, &currMark);
GetEOF(from, &fileEOF);
data = NewPtr(16384L); /* nice big buffer */
do {
size = 16384;
FSRead(from, &size, data);
FSWrite(to, &size, data);
} while(size); /* copy until EOF */
DisposPtr(data);
}